<% breadcrumb :notifications %>

<div class="row">
  <div class="col-lg-12">
    <div class="ibox float-e-margins">
      <div class="ibox-title">
        <h5>会议通知管理</h5>
      </div>
      <div class="ibox-content">

        <div class="row">

          <div class="col-xs-6">
            <h3>共找到 <strong class="text-success"><%= @attendees.total_count %></strong> 条记录</h3>
          </div>

          <div class="col-xs-6">
            <% if params[:category_id].present? %>
              <%= link_to '批量发送短信', event_notifications_path(current_event, category_id: params[:category_id]), method: :post, data: { confirm: '确认群发短信？'}, class: 'btn btn-white btn-sm pull-right' %>
            <% elsif params[:sent_sms].present? %>
              <%= link_to '批量发送短信', event_notifications_path(current_event, sent_sms: params[:sent_sms]), method: :post, data: { confirm: '确认群发短信？'}, class: 'btn btn-white btn-sm pull-right' %>
            <% elsif params[:keyword].present? %>
              <%= link_to '批量发送短信', event_notifications_path(current_event, keyword: params[:keyword]), method: :post, data: { confirm: '确认群发短信？'}, class: 'btn btn-white btn-sm pull-right' %>
            <% else %>
              <%= link_to '批量发送短信', event_notifications_path(current_event), method: :post, data: { confirm: '确认群发短信？'}, class: 'btn btn-white btn-sm pull-right' %>
            <% end %>
          </div>
        </div>

        <div class="row m-b-md m-t-md">

          <div class="col-sm-5 m-b-xs">
            <%=select_tag :category_id, options_from_collection_for_select(current_event.attendee_categories, 'id', 'name', params[:category_id]), prompt: '选择用户标签', include_blank: false, class: 'input-sm form-control input-s-sm inline'%>
          </div>

          <div class="col-sm-4 m-b-xs">
            <div data-toggle="buttons" class="btn-group">
              <% {'全部' => '0', '已发送' => '1', '未发送' => '-1'}.each do |k, v| %>
                <label class="btn btn-sm btn-white <%=params[:sent_sms] == v ? 'active' : ''%>">
                  <input type="radio" name="sent_sms" value="<%=v%>" <%=params[:sent_sms] == v ? 'checked' : ''%>> <%=k%> </label>
              <% end %>
            </div>
          </div>

          <%= form_tag event_notifications_path, method: :get do%>
            <div class="col-sm-3">
              <div class="input-group">
                <input type="text" placeholder="请输入关键字" class="input-sm form-control" name="keyword" value="<%=params[:keyword]%>">
                <span class="input-group-btn"><button type="submit" class="btn btn-sm btn-primary"> 搜索</button> </span>
              </div>
            </div>
          <% end %>

        </div>

        <div class="table-responsive">
          <table class="table table-striped">
            <thead>
            <tr>
              <th>序号</th>
              <th>姓名</th>
              <th>公司</th>
              <th>标签</th>
              <th>手机号码</th>
              <th class="text-center">短信发送状态</th>
              <th class="text-center">短信发送时间</th>
              <th>操作</th>
            </tr>
            </thead>
            <tbody>
            <% @attendees.each do |attendee| %>
              <tr>
                <td><%=attendee.attendee_number%></td>
                <td><%=attendee.name%></td>
                <td><%=attendee.company%></td>
                <td><%=attendee.category.try(:name)%></td>
                <td><%=attendee.mobile%></td>
                <td class="text-center">
                  <% if attendee.sms_sent? %>
                    <span class="label label-default" title="<%=attendee.sms_sid%>">已发送</span>
                  <% else %>
                  <% end %>
                </td>
                <td class="text-center">
                  <% if attendee.sms_sent? %>
                  <%= attendee.sms_sent_at.to_s(:short) %>
                  <% else %>
                  <% end %>
                </td>
                <td>
                  <%= link_to (attendee.sms_sent? ? '再次发送' : '发送'), event_notifications_send_sms_path(current_event, attendee), method: :post, class: 'btn btn-xs btn-white' %>
                </td>
              </tr>
            <% end %>
            </tbody>
          </table>

        </div>

        <div class="row">
          <div class="col-sm-12">
            <%= paginate @attendees %>
          </div>
        </div>

      </div>
    </div>
  </div>
</div>
